package Counter;
public class TDCounter extends Counter {
	// Counter for time-based statistics

	long lastSampleTime = 0;
	long firstSampleTime = 0;
	boolean activeState = false;
	double lastSampleSize = 0;

	// check if the state changes
	public void setActive(long time, boolean activate) {
		if (!activeState && activate) {
			firstSampleTime = time;
			activeState = true;
		} else if (activeState && !activate) {
			lastSampleTime = time;
			activeState = false;
			// add active duration the samplesizesum
			lastSampleSize += lastSampleTime - firstSampleTime;
		}
	}

	public double getUtilization(long now) {
		// dont forget to add the last active time before simulation termination
		if (activeState = true) {
			lastSampleSize += now - firstSampleTime;
		}
		return lastSampleSize / now;
	}

	@Override
	public
	void count(double value) {

	}
}
